package com.hqyj.project.controller;

import com.hqyj.project.dto.TripDto;
import com.hqyj.project.service.TripService;
import com.hqyj.project.utils.CommonResult;
import com.hqyj.project.vo.TripVo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/trip")
public class TripController {
    @Autowired
    private TripService tripService;

    @GetMapping("/info")
    @ResponseBody
    @RequiresRoles(value = {"admin","manager"},logical = Logical.OR)         //权限管理
    public CommonResult selectAllTripInfo(TripDto tripDto){
        return tripService.selectAllTripInfo(tripDto);
    }

    @PostMapping("/apply")
    @ResponseBody
    public CommonResult applyToTrip(@RequestBody TripDto tripDto){
        return tripService.applyToTrip(tripDto);
    }

    @PutMapping("/permit/{userName}")
    @ResponseBody
    @RequiresRoles(value = {"admin","manager"},logical = Logical.OR)         //权限管理
    public CommonResult permit(@PathVariable String userName){
        return tripService.permit(userName);
    }

    @PutMapping("/notPermit/{userName}")
    @ResponseBody
    @RequiresRoles(value = {"admin","manager"},logical = Logical.OR)         //权限管理
    public CommonResult notPermit(@PathVariable String userName){
        return tripService.notPermit(userName);
    }

    @GetMapping("/personal/{userName}")
    @ResponseBody
    public CommonResult personal(@PathVariable String userName){
        return tripService.selectPersonalTrip(userName);
    }

    @PutMapping("/updatestart/{userName}")
    @ResponseBody
    public CommonResult updateStart(@PathVariable String userName){
        return tripService.updateStart(userName);
    }
}
